<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../rest.css">
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .main {
            margin: 50px auto;
            width: 1280px;
            display: flex;
        }

        .magnifier {
            width: 500px;
            border: 1px red solid;
            position: relative;
        }

        .magnifier .magnifier-img {
            width: 500px;
            height: 500px;
            position: relative;
        }

        .magnifier .magnifier-img img {
            width: 500px;
            height: 500px;
        }

        .magnifier .magnifier-img .magnifiter-img-box {
            width: 200px;
            height: 200px;
            background: rgba(0, 144, 147, 0);
            position: absolute;
            left: 0;
            top: 0;
            /* display: none; */
        }

        .magnifier .magnifier-list {
            margin-top: 10px;
            width: 500px;
            height: 100px;
            display: flex;
            justify-content: space-evenly;
        }

        .magnifier .magnifier-list .list {
            flex: 1;
            width: 100px;
            align-items: center;
            display: flex;
        }

        .magnifier .magnifier-list li img {
            width: 100px;
            margin-left: 15px;
        }

        .magnifier .magnifier-effect {
            position: absolute;
            width: 600px;
            height: 600px;
            left: calc(100% + 20px);
            top: 0;
            overflow: hidden;
            display: none;
        }

        .magnifier-effect img {
            width: 1500px;
            height: 1500px;
            position: absolute;
            left: 0;
            right: 0;
            
        }

        .good-info {
            flex: 1;
            border: 1px solid black;
        }
    </style>
</head>

<body>
    <div class="main">
        <div class="magnifier">
            <div class="magnifier-img">
                <img src="./images/girlsmall1.jpg" alt="">
                <div class="magnifiter-img-box"></div>
            </div>
            <div class="magnifier-list">
                <li class="list"><img src="./images/girlsmall1.jpg"></li>
                <li class="list"><img src="./images/girlsmall2.jpg"></li>
                <li class="list"><img src="./images/girlsmall3.jpg"></li>
                <li class="list"><img src="./images/girlsmall4.jpg"></li>
            </div>
            <div class="magnifier-effect">
                <img src="./images/girlbig1.jpg" alt="">
            </div>
        </div>
        <div class="good-info"></div>
    </div>
</body>
<script>
    var box = document.getElementsByClassName('magnifiter-img-box')[0]
    var magnifier = document.getElementsByClassName('magnifier')[0]
    var magnifierImg = document.getElementsByClassName('magnifier-img')[0]
    var smallImg = document.querySelector('.magnifier-img img')
    var bigImg = document.querySelector('.magnifier-effect img')
    var magnifierEffect = document.getElementsByClassName('magnifier-effect')[0]
    var smallImgList = document.querySelectorAll('.magnifier-list .list img')
    var calcImg = magnifierImg.clientWidth / box.clientWidth


    magnifierImg.onmousemove = function (e) {
        var e = e || window.event
        magnifierEffect.style.display = 'block'
        var x = e.pageX - magnifier.offsetLeft - box.clientWidth / 2
        var y = e.pageY - magnifier.offsetTop - box.clientHeight / 2
        var maxLeft = magnifierImg.clientWidth - box.clientWidth
        var maxTop = magnifierImg.clientHeight - box.clientHeight
        x = Math.min(Math.max(0, x), maxLeft)
        y = Math.min(Math.max(0, y), maxTop)
        box.style.left = x + 'px'
        box.style.top = y + 'px'
        bigImg.style.left = -calcImg * x + 'px'
        bigImg.style.top = -calcImg * y + 'px'
        box.style.background = 'rgba(0, 144, 147, 0.5)'
    }
    //移出隐藏
    magnifierImg.onmouseout = function () {
        box.style.background = 'rgba(0, 144, 147, 0)'
        magnifierEffect.style.display = 'none'
    }




    //循环绑定切换图片
    var bigImgData = ['./images/girlbig1.jpg', './images/girlbig2.jpg', './images/girlbig3.jpg', './images/girlbig4.jpg']
    var smallImgData = ['./images/girlsmall1.jpg', './images/girlsmall2.jpg', './images/girlsmall3.jpg', './images/girlsmall4.jpg']
    for (let i = 0; i < smallImgList.length; i++) {
        smallImgList[i].onclick = function () {
            bigImg.src = bigImgData[i]
            smallImg.src = smallImgData[i]
        }
    }

</script>

</html>